//
//  MHGiftViewController.m
//  MHO
//
//  Created by Hien NV on 6/20/14.
//  Copyright (c) 2014 maihoang. All rights reserved.
//

#import "MHGiftViewController.h"
#import "Lib.h"
#import "Application.h"
#import "MHGiftDetailViewController.h"

@interface MHGiftViewController ()
@property (strong, nonatomic) IBOutlet UITableView *myGiftTableView;
@property (nonatomic, strong) IBOutlet UIView* giftView;
@property (strong, nonatomic) IBOutlet UITableView *allGiftTableView;
@property (strong, nonatomic) IBOutlet UIImageView *imageButton;
@end

@implementation MHGiftViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.tableView = self.allGiftTableView;
    self.listUrl = [NSString stringWithFormat:@"http://mobile.mho.vn/services/GameQT?idsystem=1&pageIndex=%@&pageSize=%@&key=%@", @"%d", @"%d", kServerKey];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        Application* app = [self.data objectAtIndex:indexPath.row];
        MHGiftDetailViewController* vc = [[MHGiftDetailViewController alloc] initWithNibName:@"MHGiftDetailViewController" bundle:nil];
        vc.app = app;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return self.giftView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        return self.giftView.frame.size.height;
    }
    return 0;
}
- (IBAction)allGiftButtonPressed:(id)sender {
    [self.imageButton setImage:[UIImage imageNamed:@"btn_all_gift_focus.png"]];
    [self refresh];
}
- (IBAction)myGiftButtonPressed:(id)sender {
    [self.imageButton setImage:[UIImage imageNamed:@"btn_my_gift_focus"]];
    self.data = [NSMutableArray array];
    [self.tableView reloadData];
}

@end
